// pages/video/video.js
const app = getApp();
const mod = require('../../utils/util');

const videoUrl = require('../../config').video;

Page({

  /**
   * 页面的初始数据
   */
  data: {

    page : 1
  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    var that = this;

    app.getOpenid().then(function (res) {
      if (res.status == 200) {
        mod.postData(videoUrl, {
          openid: wx.getStorageSync("usercode").openid,
          sskey: wx.getStorageSync("usercode").sskey,
          page : that.data.page
        }, function (res) {

          if (res.data.code == 1) {

            

            that.setData({
              list: res.data.data
            })
          } else {
            mod.showToast(res.data.msg)
          }

        })

      } else {
        console.log(res.data);
      }
    }); 

   
  },
  onReachBottom: function () {
    var that = this;

    wx.showLoading({
      title: '视频加载中...',
    })

    this.setData({
      page: this.data.page + 1
    }) 


    mod.postData(videoUrl, {
      openid: wx.getStorageSync("usercode").openid,
      sskey: wx.getStorageSync("usercode").sskey,
      page: that.data.page
    }, function (res) {

      if (res.data.code == 1) {

        if(res.data.data.length > 0){

          console.log(res.data.data)


          var list = that.data.list;

          for (var i = 0; i < res.data.data.length; i++) {
            list.push(res.data.data[i]);
          }

          that.setData({
            list: list
          })

          wx.hideLoading()

        }
        else{

          mod.showToast('没有更多视频了!')

        }

       


       


      } else {
        mod.showToast(res.data.msg)
      }

    })


  }

})